home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Disk / moni / FileX-src.lha / FileX-src / convert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-16  |  1.4 KB  |  114 lines

  1. #include "allprotos.h"
  2.  
  3. /*
  4.  * LONG ConvertHexstringToHexnumber(UBYTE *s,UBYTE *n)
  5.  *
  6.  * Wandelt die Zeichenkette s in Bytes n um
  7.  * und gibt die Anzahl der Bytes (nachher) zurück
  8.  */
  9.  
  10. LONG ConvertHexstringToHexnumber(UBYTE *s,UBYTE *n)
  11. {
  12.     UBYTE wert=0;
  13.     BOOL up=TRUE;
  14.     LONG anz=0;
  15.  
  16.     while(*s!=0)
  17.     {
  18.         if(isxdigit(*s))
  19.         {
  20.             if(isdigit(*s))
  21.             {
  22.                 if(up)
  23.                 {
  24.                     wert=(*s-'0')*0x10;
  25.                     up=FALSE;
  26.                 }
  27.                 else
  28.                 {
  29.                     wert+=*s-'0';
  30.                     *n++=wert;
  31.                     up=TRUE;
  32.                     anz++;
  33.                 }
  34.             }
  35.             else
  36.             {
  37.                 if(up)
  38.                 {
  39.                     wert=(ToUpper(*s)-'A'+0xa)*0x10;
  40.                     up=FALSE;
  41.                 }
  42.                 else
  43.                 {
  44.                     wert+=ToUpper(*s)-'A'+0xa;
  45.                     *n++=wert;
  46.                     up=TRUE;
  47.                     anz++;
  48.                 }
  49.             }
  50.         }
  51.         s++;
  52.     }
  53.     return(anz);
  54. }
  55.  
  56. int My_stcb_l( char *String, long *Zahl )
  57. {
  58.     int Zeichen = 0;
  59.  
  60.     *Zahl = 0;
  61.  
  62.     while(( *String == '0' ) || ( *String == '1' ) || ( *String == ' ' ))
  63.     {
  64.         if( *String != ' ' )
  65.         {
  66.             *Zahl = ( *Zahl << 1L ) + *String - '0';
  67.             Zeichen++;
  68.         }
  69.  
  70.         String++;
  71.     }
  72.  
  73.     return( Zeichen );    
  74. }
  75.  
  76. int My_stcl_b( char *String, long Zahl )
  77. {
  78.     int k;
  79.     int Zeichen = 0;
  80.  
  81.     if( Zahl == 0 )
  82.     {
  83.         *String++ = '0';
  84.         *String = 0;
  85.         return( 1 );
  86.     }
  87.  
  88.     for( k = 31; k >= 0; k-- )
  89.     if( Zahl & ( 1L << k))
  90.         break;
  91.  
  92.     if( k >= 0 )
  93.     {
  94.         *String++ = '1';
  95.         Zeichen++;
  96.         k--;
  97.  
  98.         for(; k >= 0; k-- )
  99.         {
  100.             if( Zahl & ( 1L << k))
  101.                 *String++ = '1';
  102.             else
  103.                 *String++ = '0';
  104.  
  105.             Zeichen++;
  106.         }
  107.  
  108.         *String = 0;
  109.     }
  110.  
  111.     return( Zeichen );    
  112. }
  113.  
  114.